var private ue_ya = "FFFFFE7FFDBFFBDFF7EFEFF7C3C3FBDFFBDFFBDFFBDFFBDFFBDFFBDFF81FFFFF";
var private hida_ya = "FFFFFFFFFDFFF9FFF5FFEC01DFFDBFFDBFFDDFFDEC01F5FFF9FFFDFFFFFFFFFF";
var private migi_ya = "FFFFFFFFFFBFFF9FFFAF8037BFFBBFFDBFFDBFFB8037FFAFFF9FFFBFFFFFFFFF";
var private shita_ya = "FFFFF81FFBDFFBDFFBDFFBDFFBDFFBDFFBDFC3C3EFF7F7EFFBDFFDBFFE7FFFFF";
var private ue_rot = "E7FFE1FFEC7FCF1FDFC787E7FBDFF9DFFDCFFDEFFCE7FEF7FEF7FE07FFFFFFFF";
var private hida_rot = "FFFFFBFFE3FF0BFF3BFFBCFF9E1FDFC3CFFBEFFBE47BF31BF3C3FFFFFFFFFFFF";
var private migi_rot = "FFFFFFDFFFC7FFD0FFDCFF3DF879C3FBDFF3DFF7DE27D8CFC3CFFFFFFFFFFFFF";
var private shita_rot = "FFFFFFFFFE07FEF7FEF7FCE7FDEFFDCFF9DFFBDF87E7DFC7CF1FEC7FE1FFE7FF";
var private hida_turn = "FE1FC1DFCFDFF7DFEFEFEFEFDF2FDECFDEFFDEFFDF03EFFBEFFBF7FBF9FBFE03";
var private migi_turn = "F87FFB83FBF3FBEFF7F7F7F7F4FBF37BFF7BFF7BC0FBDFF7DFF7DFEFDF9FC07F";
var private back_ya = "FFFFFE7FFDBFFBDFF7EFEFF7C183FDBFFDBFFBDFFBDFFBDFF7EFF7EFF00FFFFF";
var private front_ya = "FFFFFC3FFDBFFDBFFBDFFBDFFBDFF7EFF7EFC7E3EFF7F7EFFBDFFDBFFE7FFFFF";
var private zoomup = "03C07BDE77EE7BDE5C3A2BD4F7EFF7EFF7EFF7EF2BD45C3A7BDE77EE7BDE03C0";
var private zoomdown = "DFFBA99575AEBDBDDC3BBDBD8181F7EFF7EF8181BDBDDC3BBDBD75AEA995DFFB";
var private nearver = "EFF8EFF8EFF8E807EDF7EEF7EDF7EBF7EDD7EEA7EF77C7FF0000C7FFEFFFEFFF";
var private fit = "FFFFFFFFFFFF8441BEF7BEF7BEF78EF7BEF7BEF7BEF7BEF7BC63FFFFFFFFFFFF";
var private center = "FEFFFEFFFEFFFEFFFEFFFEFFFEFFFC7F0000FC7FFEFFFEFFFEFFFEFFFEFFFEFF";
var private save = "DFFFAEFF74FFBAFFDEFFEEFFDE80809EFF9EF800F801F820F870F820F800F800";
var private load = "001F03DF03DF001F043F0E1F041F003F005F00AEFF74FFBAFFDEFFEEFFDEFF80";
var private in1 = "DFFFAEFF74FFBAFFDEFFEE80DEFE80EEFFCEFDEEFDEEFDEEFDEEFDEEFDFEFC00";
var private in2 = "DFFFAEFF74FFBAFFDEFFEE80DEFE80CEFFB6FDF6FDEEFDDEFDBEFD86FDFEFC00";
var private in3 = "DFFFAEFF74FFBAFFDEFFEE80DEFE80CEFFB6FDF6FDCEFDF6FDB6FDCEFDFEFC00";
var private out1 = "003F7FBF7BBF73BF7BBF7BBF7BBF7BBF7BDF7FAE0174FFBAFFDEFFEEFFDEFF80";
var private out2 = "003F7FBF73BF6DBF7DBF7BBF77BF6FBF61DF7FAE0174FFBAFFDEFFEEFFDEFF80";
var private out3 = "003F7FBF73BF6DBF7DBF73BF7DBF6DBF73DF7FAE0174FFBAFFDEFFEEFFDEFF80";

//var private zoomup = "01FF7DFF7C017DFD7DFD7DFD01FDDEFDDF7DDFB5DFD5DFE5DF85DFFDC001FFFF";
//var private zoomdown = "00037FFB5FFB6FFB76FB7AFB7CFB70FB7FFB7F817FBD7FBD7FBD003DFF81FFFF";
//var private v1 = "FFEFFFEFFFF3FFF3FFFCFC3FFF3FFEBFFDBFFBFFF7FFEFFFFFFF3FFF3FFFFFFF";
//var private v2 = "FFFF80BDBEDB80FBBE9080D5FFD50055AFD5885DAB458AD5ACD708D7E658FFFF";
//var private v3 = "FFFFFFFFFFFFFFFFFFFFFC7FF83FF83FF83FFC7FFFFFFFFFFFFFFFFFFFFFFFFF";

function Hold_Save( number )
{
	var	tempdir, temp;
	var	sel[3];
	var	i, j;
	var	obj;

	tempdir = getenv( "temp" );
	if( tempdir == "" )
		tempdir = getenv( "TEMP" );

	if( substr( tempdir, -1 ) != "\\" )
		tempdir = tempdir+"\\";

	sel[0] = Select();
	SelectAll( TRUE );
	sel[1] = Select();
	PolyInvisible( FALSE );
	SelectAll( TRUE );
	sel[2] = Select();

	obj = ObjAppend( "_temp"+number, tempdir+"_temp"+number+".suf" );
	temp = WriteFile( obj );
	if( temp == FALSE )
	{
		Warning();
		Message( "ファイルのセーブに失敗したようです。\n"
			+"ディスクの容量が足りない可能性が高いですが、\n"
			+"それ以外の理由かもしれません。");
		Select( sel[1] );
		PolyInvisible( invisible_flag );
		Select( sel[0] );
		ObjDelete( obj );
		return FALSE;
	}
	ObjDelete( obj );

	hold_objnumber[number] = Objects();
	hold_invisibleflag[number] = invisible_flag;
	hold_sel[number][0] = sel[0];
	hold_sel[number][1] = sel[1];

	for( i = 0; i< hold_objnumber[number]; i++ )
	{
		SelectObj( i, TRUE, SELECT_UPDATE );
		hold_objsel[number][i] = Select();
		hold_objname[number][i] = ObjName( i );
		hold_objfile[number][i] = ObjFile( i );
		hold_objflag[number][i] = ObjEdit( i );
	}

	Select( sel[1] );
	PolyInvisible( invisible_flag );
	Select( sel[0] );
	return TRUE;
}

function Hold_Load( number )
{
	var	tempdir;
	var	add_sel, prev_sel;
	var	i, obj;

	tempdir = getenv( "temp" );
	if( tempdir == "" )
		tempdir = getenv( "TEMP" );

	if( substr( tempdir, -1 ) != "\\" )
		tempdir = tempdir+"\\";

	prev_sel = Select();
	SelectAll( FALSE, SELECT_UPDATE );
	i = ReadFile( tempdir+"_temp"+number+".suf" );
	if( i < 0 )
	{
		Message( "ファイルの読み込みに失敗しました" );
		Select( prev_sel );
		return;
	}

	PolyInvisible( FALSE );
	SelectAll( TRUE, SELECT_XOR );
	PolyDelete();
	while( Objects() > 1 )
		ObjDelete( 0 );

	for( i = 0; i< hold_objnumber[number]; i++ )
	{
		obj = ObjAppend( hold_objname[number][i], hold_objfile[number][i] );
		Select(hold_objsel[number][i]);
		ObjChange( obj );
		ObjEdit( obj ,hold_objflag[number][i] );
	}

	if( ObjDelete( 0 ) == FALSE )
		Warning();
	Select( hold_sel[number][1] );
	invisible_flag = hold_invisibleflag[number];
	PolyInvisible( invisible_flag );
	Select( hold_sel[number][0] );
	UpdateAll();
	quit_flag = TRUE;
}

function private FuncMoveUpper()
	PersMove( 0, 0, -100 );

function private FuncMoveLeft()
	PersMove( 0, -100, 0 );

function private FuncMoveRight()
	PersMove( 0, 100, 0 );

function private FuncMoveLower()
	PersMove( 0, 0, 100 );

function private FuncRollUpper()
	PersRot( 0, -10, 0 );

function private FuncRollLeft()
	PersRot( 0, 0, 10 );

function private FuncRollRight()
	PersRot( 0, 0, -10 );

function private FuncRollLower()
	PersRot( 0, 10, 0 );

function private FuncTurnLeft()
	PersRot( -10, 0, 0 );

function private FuncTurnRight()
	PersRot( 10, 0, 0 );

function private FuncMoveBack()
	PersMove( -100, 0, 0 );

function private FuncMoveFront()
	PersMove( 100, 0, 0 );

function private FuncZoomUp()
	ZoomUp();

function private FuncZoomDown()
	ZoomDown();

function private FuncNearVertex()
	_Vertex();

function private FuncFit()
	Fit();

function private FuncCenter()
	DispCenter();

function private FuncHoldSave0()
{
	var	temp;
	temp = Hold_Save( 0 );
	if( temp == TRUE )
	{
		ButtonEnable( load0_id, BUTTON_ENABLE );
		UpdateButton( load0_id );
	}
}
function private FuncHoldLoad0()
	Hold_Load( 0 );

function private FuncHoldSave1()
{
	var	temp;
	temp = Hold_Save( 1 );
	if( temp == TRUE )
	{
		ButtonEnable( load1_id, BUTTON_ENABLE );
		UpdateButton( load1_id );
	}
}
function private FuncHoldLoad1()
	Hold_Load( 1 );

function private FuncHoldSave2()
{
	var	temp;
	temp = Hold_Save( 2 );
	if( temp == TRUE )
	{
		ButtonEnable( load2_id, BUTTON_ENABLE );
		UpdateButton( load2_id );
	}
}
function private FuncHoldLoad2()
	Hold_Load( 2 );

function MakeButton()
{
	var	const	W0 = 0;
	var	const	W1 = BUTTON_WIDTH/2;
	var	const	W2 = BUTTON_WIDTH;
	var	const	M = BUTTON_ENABLE | BUTTON_REPEAT;

	moveupper_id =	CreateButton( W1, BUTTON_HEIGHT* 0   ,ue_ya, FuncMoveUpper, M);
	moveleft_id =	CreateButton( W0, BUTTON_HEIGHT* 1   ,hida_ya, FuncMoveLeft, M);
	moveright_id =	CreateButton( W2, BUTTON_HEIGHT* 1   ,migi_ya, FuncMoveRight, M);
	movelower_id =	CreateButton( W1, BUTTON_HEIGHT* 2   ,shita_ya, FuncMoveLower, M);
	rotupper_id =	CreateButton( W1, BUTTON_HEIGHT* 7/2 ,ue_rot, FuncRollUpper, M);
	rotleft_id =	CreateButton( W0, BUTTON_HEIGHT* 9/2 ,hida_rot, FuncRollLeft, M);
	rotright_id =	CreateButton( W2, BUTTON_HEIGHT* 9/2 ,migi_rot, FuncRollRight, M);
	rotlower_id =	CreateButton( W1, BUTTON_HEIGHT*11/2 ,shita_rot, FuncRollLower, M);
	turnleft_id =	CreateButton( W0, BUTTON_HEIGHT* 7   ,hida_turn, FuncTurnLeft, M);
	turnright_id =	CreateButton( W2, BUTTON_HEIGHT* 7   ,migi_turn, FuncTurnRight, M);
	moveback_id =	CreateButton( W1, BUTTON_HEIGHT*17/2 ,back_ya, FuncMoveBack, M);
	movefront_id =	CreateButton( W1, BUTTON_HEIGHT*19/2 ,front_ya, FuncMoveFront, M);

	zoomup_id =	CreateButton( W0, BUTTON_HEIGHT*24/2 ,zoomup, FuncZoomUp);
	zoomdown_id =	CreateButton( W2, BUTTON_HEIGHT*24/2 ,zoomdown, FuncZoomDown);
	fit_id =	CreateButton( W0, BUTTON_HEIGHT*26/2 ,fit, FuncFit);
	center_id =	CreateButton( W2, BUTTON_HEIGHT*26/2 ,center, FuncCenter);
	nearvertex_id =	CreateButton( W1, BUTTON_HEIGHT*29/2 ,nearver, FuncNearVertex);
	allsave_id =	CreateButton( W0, BUTTON_HEIGHT*32/2 ,save, SaveAll );
	load_id =	CreateButton( W2, BUTTON_HEIGHT*32/2 ,load, Load );

	save0_id =	CreateButton( W0, BUTTON_HEIGHT*35/2 ,in1, FuncHoldSave0 );
	load0_id =	CreateButton( W2, BUTTON_HEIGHT*35/2 ,out1, FuncHoldLoad0 );
	save1_id =	CreateButton( W0, BUTTON_HEIGHT*37/2 ,in2, FuncHoldSave1 );
	load1_id =	CreateButton( W2, BUTTON_HEIGHT*37/2 ,out2, FuncHoldLoad1 );
	save2_id =	CreateButton( W0, BUTTON_HEIGHT*39/2 ,in3, FuncHoldSave2 );
	load2_id =	CreateButton( W2, BUTTON_HEIGHT*39/2 ,out3, FuncHoldLoad2 );

	ButtonEnable( load0_id, BUTTON_DISABLE );
	ButtonEnable( load1_id, BUTTON_DISABLE );
	ButtonEnable( load2_id, BUTTON_DISABLE );
	UpdateButton();

//	CreateButton(0, BUTTON_HEIGHT*17/2,
//		"5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa5555aaaa",
//		FuncRollLower);
//	UpdateAll();
}
